<%@ page import="com.party.core.model.system.TargetType" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>${ad == null ?'发布':'编辑'}事件</title>
    <%@include file="../include/commonFile.jsp" %>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/ui/ad/publish_form.css">
</head><body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <!-- 正文请写在这里 -->
            <div class="add-form-content">
            <form id="myForm" class="layui-form mt20" method="post" action="${ctx}/analysis/event/saveOrupdate.do">
                <input type="hidden" name="id" value="${se.id}"/>
                <div class="layui-form-item">
                    <label class="layui-form-label">事件名称<span class="f-verify-red">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="name" lay-verify="name" placeholder="请输入事件名称"
                               class="layui-input" value="${se.name}" style="width: 500px;">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">事件code<span class="f-verify-red">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="code"   lay-verify="code" placeholder="请输入事件code"
                               class="layui-input" value="${se.code}" style="width: 500px;">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">事件类型<span class="f-verify-red">*</span></label>
                    <div class="layui-input-block">
                        <input type="radio" name="type" lay-verify="type" value="1"
                               title="网页端" ${se.type == 1 ? 'checked="checked"' : ''} />
                        <input type="radio" name="type" lay-verify="type" value="2"
                               title="移动端" ${se.type == 2 ? 'checked="checked"' : ''} />
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <a href="javascript:void(0)" class="layui-btn layui-btn-danger" lay-submit lay-filter="*">立即提交</a>
						<a href="${ctx}/analysis/event/list.do" class="layui-btn layui-btn-primary">取消</a>
                    </div>
                </div>
            </form>
            </div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>
</div>

<script>

    $(function () {  layui.use(['form'], function () {
        var form = layui.form, laydate = layui.laydate;

        //自定义验证规则
        form.verify({
            name: function (value) {
                if (value == "") {
                    return "请输入事件名称";
                }
                if (eventNameIsValid(value)){
                    return "事件名称已存在";
                }
            },
            code: function (value) {
                if (value == "") {
                    return "请输入事件code";
                }
                if (eventCodeIsValid(value)){
                    return "事件code已存在";
                }
            }
        });
        //监听提交
        form.on('submit', function (data) {
            txz.submitObject(data.elem, function (callBack) {
                var action = $("#myForm").attr("action");
                $.post(action, $('#myForm').serialize(), function (res) {
                    typeof callBack === 'function' && callBack();
                    if (res.success) {
                        util.layerMsgSuccess("提交成功", function () {
                            location.href = "${ctx}/analysis/event/list.do";
                        })
                    } else {
                        util.layerMsgError("提交失败")
                    }
                });
            });
            return false;
        });
    });
    })
    function eventNameIsValid(name) {

        var bl = false
        $.ajaxSettings.async = false;
        $.post("${ctx}/analysis/event/eventIsValid.do", {"name": name}, function (res) {
            bl = res.success;

        });
        $.ajaxSettings.async = true;
        return bl;
    }
    function eventCodeIsValid(code) {
        var bl = false
        $.ajaxSettings.async = false;
        $.post("${ctx}/analysis/event/eventIsValid.do", {"code": code}, function (res) {
            bl = res.success;

        });
        $.ajaxSettings.async = true;
        return bl;
    }

</script>
<script type="text/javascript">
    txz.initHeader({
        nav:[{
            name: '事件分析',
            href:'${ctx}/analysis/event/list.do',
        },{
            name: '${member == null ? '发布' : '编辑'}事件',
            curr: true
        }],
        btns:[{
            type:'back'
        }]
    });
    
</script>
</body>
</html>